#include "deposit_info.h"
#include "QSqlDatabase"
#include "QSqlQuery"
#include "QDebug"
#include "QMessageBox"
#include "QSqlError"
deposit_info::deposit_info()
{

}

void deposit_info::setCustTelnumber(const QString &telnumber)
{
    cust_telnumber = telnumber;
}

void deposit_info::setCustName(const QString& name)
{
    cust_name = name;
}
void deposit_info::setCustPassword(const QString& password)
{
    cust_password = password;
}
void deposit_info::setCustAddress(const QString& address)
{
    cust_address = address;
}
void deposit_info::setSavingsType(const QString& type)
{
    savings_type = type;
}
void deposit_info::setSavingsAmount(const QString& amount)
{
    savings_amount = amount;
}

void deposit_info::setSavingsTime(const QString &time)
{
    savings_time = time;
}
void deposit_info::setIsLost(const QString& islost)
{
    is_lost = islost;
}
void deposit_info::setLostTime(const QString& losttime)
{
    lost_time = losttime;
}
void deposit_info::setClerkName(const QString& name)
{
    clerk_name = name;
}
void deposit_info::setClerkEmployeeid(const QString& id)
{
    clerk_employeeid = id;
}
void deposit_info::setReviewStatus(const QString& status)
{
    review_Status = status;
}

void deposit_info::insertToDB()
{
    QSqlDatabase sqlite = QSqlDatabase::database("deposit");
    QSqlQuery query(sqlite);
    //先查询数据是否存在，若存在则提示
    query.prepare("SELECT * FROM DEPOSIT WHERE custtelnumber = ? ");
    qDebug() << this->cust_telnumber;
    query.addBindValue(this->cust_telnumber);
    if(!query.exec())
    {
        return;
    }

    if(query.next())
    {
        QMessageBox box;
        box.setWindowTitle("warning");
        box.setText("您已经办理过开户了");
        box.setIcon(QMessageBox::Warning);
        box.exec();
        return;
    }
    else
    {
        query.prepare("INSERT INTO DEPOSIT(custtelnumber,custname,custpassword,custaddress,\
                        savingstype,savingsamount,savingstime,islost,losttime,clerkname,clerkemployeeid,reviewstatus)\
               VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");
    }
    query.addBindValue(cust_telnumber);query.addBindValue(cust_name);query.addBindValue(cust_password);
    query.addBindValue(cust_address);query.addBindValue(savings_type);query.addBindValue(savings_amount);query.addBindValue(savings_time);
    query.addBindValue(is_lost);query.addBindValue(lost_time);query.addBindValue(clerk_name);
    query.addBindValue(clerk_employeeid);query.addBindValue(review_Status);
    if(query.exec())
    {
        QMessageBox box;
        box.setWindowTitle("completed");
        box.setText("成功申请开户");
        box.setIcon(QMessageBox::Information);
        box.exec();
    }
}
